from nltk.corpus import gutenberg
from nltk.probability import ConditionalFreqDist
from random import choice

cfd = ConditionalFreqDist()

prev_word = None
files = [r'first.txt',r'second.txt',r'third.txt',r'fourth.txt']

file = choice(files)
print file
for word in gutenberg.words(choice(file)):
    cfd[prev_word].inc(word)
    prev_word = word

starters = ['Therefore','After','Sherlock','England']

word = choice(starters)
print word

"""
i = 1

while i < 20:
    print word,
    lwords = cfd[word].samples()
    follower = choice(lwords)
    word = follower
    i += 1


"""
